package com.xiaomi.service.impl;

import com.xiaomi.entity.ShopSpu;
import com.xiaomi.mapper.ShopSkuMapper;
import com.xiaomi.mapper.ShopSpuMapper;
import com.xiaomi.service.ShopSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ShopSpuServiceImpl
 * @Description TODO
 * @Author yp
 * @Date 2021/11/28 12:14
 * @Version 1.0
 **/
@Service
public class ShopSpuServiceImpl implements ShopSpuService {
    @Autowired
    private ShopSpuMapper shopSpuMapper;
    @Autowired
    private ShopSkuMapper shopSkuMapper;

    @Override
    public List<ShopSpu> pageSearch(Map<String,Object> pars) throws Exception {
        List<ShopSpu> skuList= shopSpuMapper.pageSearch(pars);
        for (ShopSpu spu:skuList){
            spu.setSku(shopSkuMapper.selectBySpuId(spu.getId()));
        }
        return skuList;
    }

    @Override
    public Integer getCount(Map<String,Object> pars) throws Exception {
        return shopSpuMapper.getCount(pars);
    }
    @Override
    @Transactional
    public void insert(ShopSpu shopSpu) throws Exception {
        shopSpuMapper.insert(shopSpu);
    }

    @Override
    @Transactional
    public void update(ShopSpu shopSpu) throws Exception {
        shopSpuMapper.update(shopSpu);
    }

    @Override
    public void delete(Integer id) throws Exception {
        shopSpuMapper.delete(id);
    }
}
